package com.finger.educms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.finger.educms.entity.CrmBanner;
import com.finger.educms.mapper.CrmBannerMapper;
import com.finger.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author finger
 * @since 2022-01-12
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    // key可选属性，可以使用 SpEL 标签自定义缓存的key
    // value 缓存名，必填，它指定了你的缓存存放在哪块命名空间
    @Cacheable(key = "'IndexBannerList'",value = "banner")
    @Override
    public List<CrmBanner> selectAllBanner() {
        QueryWrapper<CrmBanner> crmBannerQueryWrapper = new QueryWrapper<>();

        crmBannerQueryWrapper.orderByDesc("id");

        crmBannerQueryWrapper.last("limit 2");

        List<CrmBanner> list = baseMapper.selectList(crmBannerQueryWrapper);

        return list;
    }
}
